﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace ClientTest
{
    class Program
    {
        static void Main(string[] args)
        {
            const int PORT = 1979;
            const string IPv6_ADDR = "fe80::9e1:374d:4ab3:fcb0";//"fe80::9e1:374d:4ab3:fcb0";//"::1";//"fe80::4cff:fe4f:4f50";

            if (!Socket.OSSupportsIPv6)
            {
                Console.Error.WriteLine("Your system does not support IPv6\r\n" +
                    "Check you have IPv6 enabled and have changed machine.config");
                return;
            }
            IPAddress ipa = IPAddress.Parse(IPv6_ADDR);
            IPEndPoint ipeh = new IPEndPoint(ipa, PORT);
            try
            {
                Socket connection = new Socket(
                    AddressFamily.InterNetworkV6,
                    SocketType.Stream,
                    ProtocolType.Tcp);
                connection.Connect(ipeh);

                byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes("hello world");
                for (int x = 0; x < 10; x++)
                {
                    Console.WriteLine("TX: " + System.Text.ASCIIEncoding.ASCII.GetString(b));
                    connection.Send(b);

                    Thread.Sleep(1000);
                }

                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.Read();
            }
        }
    }
}
